//package com.platform.mall.security.core.clientdetails;
//
//
//import com.platform.mall.common.enums.PasswordEncoderTypeEnum;
//import com.platform.mall.mapper.SysOauthClientMapper;
//import com.platform.mall.model.dto.AuthClientDTO;
//import lombok.RequiredArgsConstructor;
//import org.springframework.cache.annotation.Cacheable;
//import org.springframework.dao.EmptyResultDataAccessException;
//import org.springframework.security.oauth2.provider.ClientDetails;
//import org.springframework.security.oauth2.provider.ClientDetailsService;
//import org.springframework.security.oauth2.provider.NoSuchClientException;
//import org.springframework.security.oauth2.provider.client.BaseClientDetails;
//import org.springframework.stereotype.Service;
//
///**
// * OAuth2 客户端信息
// */
//@Service
//@RequiredArgsConstructor
//public class ClientDetailsServiceImpl implements ClientDetailsService {
//
//    private final SysOauthClientMapper clientMapper;
//
//    @Override
////    @Cacheable(cacheNames = "auth", key = "'oauth-client:'+#clientId")
//    public ClientDetails loadClientByClientId(String clientId) {
//        try {
//            AuthClientDTO client = clientMapper.getOAuth2ClientById(clientId);
//            if (client != null) {
//                BaseClientDetails clientDetails = new BaseClientDetails(
//                        client.getClientId(),
//                        client.getResourceIds(),
//                        client.getScope(),
//                        client.getAuthorizedGrantTypes(),
//                        client.getAuthorities(),
//                        client.getWebServerRedirectUri()
//                );
//                clientDetails.setClientSecret(PasswordEncoderTypeEnum.NOOP.getPrefix() + client.getClientSecret());
//                clientDetails.setAccessTokenValiditySeconds(client.getAccessTokenValidity());
//                clientDetails.setRefreshTokenValiditySeconds(client.getRefreshTokenValidity());
//                return clientDetails;
//            } else {
//                throw new NoSuchClientException("No client with requested id: " + clientId);
//            }
//        } catch (EmptyResultDataAccessException var4) {
//            throw new NoSuchClientException("No client with requested id: " + clientId);
//        }
//    }
//}
